export default {
  // 驼峰转换  RO_NO --> roNo
  camelCase(str) {
    let arr = str.split('_');
    let upper = arr.map((val, index) => {
      let lowStr = val.toLowerCase();
      if (index) {
        lowStr = lowStr.charAt(0).toLocaleUpperCase() + lowStr.slice(1);
      }
      return lowStr;
    });
    return upper.join('');
  },
  // {对象} 所有字段转驼峰
  camelCaseObject(obj) {
    const newObj = {};
    const keys = Object.keys(obj);
    keys.forEach((key, i) => {
      newObj[this.camelCase(key)] = obj[key];
    });
    return newObj;
  },
  /**
   * 把对象中 值 为null 和 undefined 转 空字符串
   * @param {Object} obj
   * @return {Object} 新对象
   */
  filteObjNull(obj) {
    const keys = Object.keys(obj);
    const _obj = {};
    keys.forEach(key => {
      if (obj[key] === null || obj[key] === undefined) {
        _obj[key] = '';
      } else {
        _obj[key] = obj[key];
      }
    });
    return _obj;
  }
};
